

var   manId;
/**
 * 初始化页面
 */

$(function(){
	initData();
	initLinkMan();	
})


function initLinkMan(){
	queryLinkMan();
}


function initData(){
	manId=[];
	 for (var i = 0; i < chenckMan.length; i++) {
		 manId.push(""+ chenckMan[i].linkmanId);
	}
	 
}

/**查询联系人
 * @returns
 */
function queryLinkMan(){
	var linkGroup= [ {code : 'thirdPartyLinkmansId',name : 'checkBox',width : 10},
	                {code : 'linkmanName',name : '姓名'}, 
	                {code : 'mobilePhone',name : '电话'}, 
	                {code : 'email',name : '邮件'}, 
	                {code : 'department',name : '所属部门'}, 
	                {code : 'pany',name : '所属公司'},
	                ];
	var parm = {
		url : basePath + '/radar/linkGroup/getManList.do',
		divID : 'groupLinkMan',
		afterQuery:'afterselect'
			};
	// 常规参数
	var data = {
		'linkmanName' : $("#linkmanName").val(),
		'mobilePhone': $("#mobilePhone").val(),
		'email': $("#email").val(),
		'pany': $("#pany").val(),
		'department': $("#department").val(),
		'operate': $("#operate").val(),
		'groupId':groupId
		
	}; // 赛选

	easyQuery(linkGroup, parm, data);
}



function  afterselect(){
	  for (var i = 0; i < manId.length; i++) {
		  $("input[type='checkbox'][nodeId='"+manId[i]+"']").prop("checked", true);
	}
}

// 保存绑定的设备
function savelinkMans(){
     var checkBox='';
	for (var i = 0; i < manId.length; i++) {
		checkBox=checkBox+manId[i]+',';
	}
	if(checkBox.length>0){
		checkBox=checkBox.substring(0,(checkBox.length-1));
	}

	$.ajax({
		url:basePath+"/radar/linkGroup/savelinKMans.do",
	  	type:"post",
	  	dataType:"json",
	    data:{
		    "linkGroupId":groupId,
		    "linkMan":checkBox,
       },
       success: function(result){
    	   var result = result.data;
    	   if(result.indexOf("success")==0){
    		   parent.layer.msg('保存成功！', {icon : 1,time : 2000});  		
    		   closeWindow();
    	   }else{
    		   parent.layer.msg('保存失败！',{icon : 1,time : 2000}); 
    		   closeWindow();
    	   }
       }
	});
}

/**复选框 
 * @param f
 */
function  manucheck(f){
     var id=$(f).attr("nodeId");
     if($(f).attr('checked')){
    	 manId.push(id);
     }else{
    	 var index = manId.indexOf(id);
    	 if (index > -1) {
    		 manId.splice(index, 1);
          }
	}
}


/**复选框全选后操作
 * @param f
 */
function afterSelectAll(f){	
	 var divID=$(f).attr("divID");
	 $("input[type='checkbox'][divID='"+divID+"'][nodeId]").each(function (){
		 var index = manId.indexOf($(this).attr("nodeId"));
		 if($(f).attr('checked')){
			 //判断数组中是否含有  不含有再添加			
	    	 if (index == -1) {
	    		 manId.push($(this).attr("nodeId"));
	          }			
	     }else{	    	
	    	 if (index > -1) {
	    		 manId.splice(index, 1);
	          }
		} 
	 });   
}
